#include<bits/stdc++.h>
using namespace std;
int n,m,l,V,T;
int d[100020],v[100020],a[100020],p[100020];
int vc[100020];
vector<int>G[100020];
bool cmp(vector<int> z,vector<int> y){
    return z.size()<y.size();
}
int main(){
    ios::sync_with_stdio(false);
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    cin>>T;
    while(T--){
        memset(G,0,sizeof(G));
        memset(vc,0,sizeof(vc));
        cin>>n>>m>>l>>V;
        for(int i=1;i<=n;i++) cin>>d[i]>>v[i]>>a[i];
        for(int i=1;i<=m;i++) cin>>p[i];
        int ans=0,j=-1,sum=0;
        for(int i=1;i<=n;i++){
            j=-1;
            if(a[i]<0){
                for(int k=1;k<=m;k++){
                    if(p[k]>=d[i]){
                        j=k;
                        break;
                    }
                }
            }
            else j=m;
            if(a[i]<0&&j!=-1){
                sum=d[i]+(V*V-v[i]*v[i])/2/a[i];
                for(int sss=j;p[sss]<=sum&&p[sss]>=d[i]&&sss<=n;sss++) G[sss].push_back(i),vc[i]++;
                if(p[j]<sum) ans++;
            }
            else if(a[i]>0&&j!=-1){
                sum=d[i]+(V*V-v[i]*v[i])/2/a[i];
                for(int sss=1;sss<=n;sss++){
                    if(p[sss]>=sum){
                        G[sss].push_back(i);
                        vc[i]++;
                    }
                }
                if(p[j]>sum) ans++;
            }
            else if(j!=-1){
                if(v[i]>V) ans++;
                for(int sss=j;v[i]>V&&sss<=n;sss++) G[sss].push_back(i),vc[i]++;
            }
        }
        sum=0;
        bool b;
        sort(G+1,G+m+1,cmp);
        for(int sss=1;sss<=m;sss++){
            b=0;
            for(int ss=0;ss<G[sss].size();ss++){
                if(vc[G[sss][ss]]==1){
                    b=1;
                    break;
                }
            }
            if(!b){
                sum++;
                for(int i=0;i<G[sss].size();i++) vc[G[sss][i]]--;
            }
        }
        cout<<ans<<" "<<sum<<endl;
    }
    return 0;
}